package com.kyh.util.wangshen;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;

public class ServletUtil {
	private static final Logger logger = Logger.getLogger(ServletUtil.class);
	
	/**
	 * ajax return json
	 * @param response
	 * @param jsonArray
	 */
	public static void printJSON(HttpServletResponse response, JSONObject json){
		PrintWriter out = null;
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		try{
			out = response.getWriter();
			out.println(json.toJSONString());
		}catch (Exception e){
			logger.error("printJSON出错",e);
		}
		finally{
			if(out!=null)
				out.close();
		}
	}
}
